#include "SquareBumper.h"

SquareBumper::SquareBumper()
{
	_location = vector3( 100, 100, 0 );
	_l = 10;
	_w = 10;

	init();
}
SquareBumper::SquareBumper( vector3 location, double l, double w )
{
	_location = location;
	_l = l;
	_w = w;

	init();
}


SquareBumper::~SquareBumper(void)
{
	//delete points;
}

void SquareBumper::init()
{
	points = new vector3[ 4 ];
	points[ 0 ] = _location;
	points[ 1 ] = vector3( _location.getX(),	_location.getY() + _l,	_location.getZ()	);
	points[ 2 ] = vector3( _location.getX()+_w,	_location.getY() + _l,	_location.getZ()	);
	points[ 3 ] = vector3( _location.getX()+_w,	_location.getY(),		_location.getZ()	);
	_color = GREEN;
}

void SquareBumper::Render()
{
	DrawTools::drawQuad( points[0],points[1],points[2],points[3], _color );
}

bool SquareBumper::isCollidingWithBall( Ball * ball )
{
	for( int i = 0; i < 4; i++ ){
		int cur_i = i;
		int next_i = ( i+1 >= 4 ) ? 0 : i+1 ;

		bool isColliding = CollisionTool::checkCollision( *ball, points[ cur_i ], points[ next_i ] );
		if( isColliding ){
			_color = BLUE;
			return true;
		}
	}
	_color = GREEN;
	return false;
}